//
//  ViewController.m
//  提示框
//
//  Created by Apple-Mini on 16/3/9.
//  Copyright © 2016年 微赢互动. All rights reserved.
//

#import "ViewController.h"
#define screen_Width  [UIScreen mainScreen].bounds.size.width
#define screen_Height  [UIScreen mainScreen].bounds.size.height
@interface ViewController (){

    UIAlertView *promptAlert;
}

@end

@implementation ViewController
- (void)showMessage:(NSString *)message
{
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    UIView *showview =  [[UIView alloc]init];
    showview.backgroundColor = [UIColor blackColor];
    showview.frame = CGRectMake(1, 1, 1, 1);
    showview.alpha = 1.0f;
    showview.layer.cornerRadius = 5.0f;
    showview.layer.masksToBounds = YES;
    [window addSubview:showview];
    
    UILabel *label = [[UILabel alloc]init];
    CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:30] constrainedToSize:CGSizeMake(300, 9000)];
    label.frame = CGRectMake(10, 5, LabelSize.width + 20, LabelSize.height);
    label.text = message;
    label.textColor = [UIColor whiteColor];
    label.textAlignment = UITextAlignmentLeft;
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont boldSystemFontOfSize:30];
    [showview addSubview:label];
    showview.frame = CGRectMake((screen_Width - LabelSize.width - 20)/2, screen_Height - 100, LabelSize.width+50, LabelSize.height*2 );
    [UIView animateWithDuration:2.0 animations:^{
        showview.alpha = 0;
    } completion:^(BOOL finished) {
        [showview removeFromSuperview];
    }];
}

- (IBAction)showAlert:(UIButton *)sender {
    NSLog(@"曾经有一段真挚的爱情摆在我的面前");
    [self showMessage:@"O(∩_∩)O...."];
    /*promptAlert = [[UIAlertView alloc] initWithTitle:@"提示:" message:@"添加收藏成功!" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
    [promptAlert show];
    
    [NSTimer scheduledTimerWithTimeInterval:0.5f
                                     target:self
                                   selector:@selector(timer)
                                   userInfo:promptAlert
                                    repeats:NO];*/
}
- (void)timerFireMethod:(NSTimer*)theTimer
{
    UIAlertView *promptAlert = (UIAlertView*)[theTimer userInfo];
    
    //promptAlert =NULL;
    [NSTimer scheduledTimerWithTimeInterval:2.5f
                                     target:self
                                   selector:@selector(timer)
                                   userInfo:promptAlert
                                    repeats:NO];
}

- (void)timer{
  [promptAlert dismissWithClickedButtonIndex:0 animated:NO];
}


@end
